#include <bits/stdc++.h>
#ifndef DEBUG
#define debug
#endif
using namespace std;
using i64 = int64_t;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  const string pattern = "WING";
  vector<int> cnt(4);
  for (auto &c : cnt) cin >> c;
  vector<int> trans(676);
  auto get_id = [&](char a, char b) {
    return (a - 'A') * 26 + (b - 'A');
  };
  for (int i = 0; i < 4; i ++) {
    while (cnt[i] --) {
      string s;
      cin >> s;
      trans[get_id(s[0], s[1])] |= 1 << i;
    }
  }
  string str;
  cin >> str;
  int n = str.size();
  vector<vector<int>> dp(n, vector<int>(n));
  for (int l = n - 1; l >= 0; l --) {
    for (int r = l + 1; r < n; r ++) {
      if (l + 1 == r) {
        dp[l][r] = trans[get_id(str[l], str[r])];
      } else {
        for (int i = 0; i < 4; i ++) {
          if (dp[l][r - 1] >> i & 1) {
            dp[l][r] |= trans[get_id(pattern[i], str[r])];
          }
          if (dp[l + 1][r] >> i & 1) {
            dp[l][r] |= trans[get_id(str[l], pattern[i])];
          }
        }
        for (int k = l + 1; k + 1 < r; k ++) {
          // dp[l][k], dp[k + 1][r];
          for (int i = 0; i < 4; i ++) {
            if ((dp[l][k] >> i & 1) == 0) continue;
            for (int j = 0; j < 4; j ++) {
              if ((dp[k + 1][r] >> j & 1) == 0) continue;
              dp[l][r] |= trans[get_id(pattern[i], pattern[j])];
            }
          }
        }
      }
    }
  }
  if (dp[0][n - 1] == 0) {
    cout << "The name is wrong!" << endl;
    return 0;
  }
  for (int i = 0; i < 4; i ++) {
    if (dp[0][n - 1] >> i & 1) {
      cout << pattern[i];
    }
  }
  cout << endl;
}